package com.roy.galaxy.collection;

import java.util.Collection;
import java.util.Iterator;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author gang.wang1903@xiaobao100.cn
 * @Date: 2019-10-09 17:18
 *
 * 利用concurrenthashmap实现
 */
public class ConcurrentHashSet<E> implements Set<E> {

    private final  Object object = new Object();

    private final ConcurrentHashMap concurrentHashMap = new ConcurrentHashMap();

    @Override
    public int size() {
        return 0;
    }

    @Override
    public boolean isEmpty() {
        return concurrentHashMap.isEmpty();
    }

    @Override
    public boolean contains(Object o) {
        return concurrentHashMap.contains(o);
    }

    @Override
    public Iterator<E> iterator() {
        return concurrentHashMap.keySet().iterator();
    }

    @Override
    public Object[] toArray() {
        return new Object[0];
    }

    @Override
    public <T> T[] toArray(T[] a) {
        return null;
    }

    @Override
    public boolean add(E e) {
        return concurrentHashMap.put(e,object) != null;
    }

    @Override
    public boolean remove(Object o) {
        return concurrentHashMap.remove(o,object);
    }

    @Override
    public boolean containsAll(Collection<?> c) {
        return false;
    }

    @Override
    public boolean addAll(Collection<? extends E> c) {
        return false;
    }

    @Override
    public boolean retainAll(Collection<?> c) {
        return false;
    }

    @Override
    public boolean removeAll(Collection<?> c) {
        return false;
    }

    @Override
    public void clear() {

    }
}
